package com.ruoyi.system.service.impl;

import com.baomidou.mybatisplus.extension.conditions.query.LambdaQueryChainWrapper;
import com.baomidou.mybatisplus.extension.conditions.update.LambdaUpdateChainWrapper;
import com.ruoyi.system.domain.SysRoleMenu;
import com.ruoyi.system.mapper.SysRoleMenuMapper;
import com.ruoyi.system.service.ISysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * @Description: 角色菜单服务类
 * @Author: zhoukeyao    //作者
 * @CreateDate: 2025/3/28 14:00	//创建时间
 * @UpdateUser: 更新人
 * @UpdateDate: 2025/3/28 14:00	//更新时间
 */
@Service
public class SysRoleMenuServiceImpl implements ISysRoleMenuService {
    @Autowired
    private SysRoleMenuMapper roleMenuMapper;

    @Override
    public int saveBatch(List<SysRoleMenu> list) {
        return roleMenuMapper.insert(list).size();
    }

    @Override
    public void deleteByRoleId(Long roleId) {
        new LambdaUpdateChainWrapper<>(roleMenuMapper)
                .eq(SysRoleMenu::getRoleId, roleId)
                .remove();
    }

    @Override
    public void deleteByRoleIds(List<Long> roleIds) {
        new LambdaUpdateChainWrapper<>(roleMenuMapper)
                .in(SysRoleMenu::getRoleId, roleIds)
                .remove();
    }

    @Override
    public List<SysRoleMenu> selectByRoleIds(List<Long> roleId) {
        return new LambdaQueryChainWrapper<>(roleMenuMapper)
                .in(SysRoleMenu::getRoleId, roleId)
                .list();
    }

    @Override
    public List<SysRoleMenu> selectByRoleId(Long roleId) {
        return new LambdaQueryChainWrapper<>(roleMenuMapper)
                .eq(SysRoleMenu::getRoleId, roleId)
                .list();
    }

    @Override
    public boolean exists(Long menuId) {
        return new LambdaQueryChainWrapper<>(roleMenuMapper)
                .eq(SysRoleMenu::getMenuId, menuId)
                .exists();
    }
}
